package com.hrpc.core;

import java.util.concurrent.TimeUnit;

public class hRpcShutdownHook extends Thread{
    @Override
    public void run() {
        //1.打开挡板 (线程安全的boolean)
        ShutDownHolder.BAFFLE.set(true);
        //2，等待计数器归零，正常的请求处理结束
        //等待归零继续执行countDownLatch
        long start = System.currentTimeMillis();
        while (true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (ShutDownHolder.REQUEST_COUNT.sum() == 0L
            || System.currentTimeMillis()-start > 10000){
                break;
            }
        }
        //3.阻塞结束后放行，执行其他操作：如释放资源
        //run执行完程序就结束了
    }
}
